def admin_users():
if not session.get('user').get('is_admin'):
abort(401)
- users = query_db('select * from users order by id desc')
+ users = query_db('select *, roles.name as rolename from (select *, name as username from users join user_role on id=id_user order by id desc) join roles on id_role=roles.id')
+ # :TODO:maethor:20120530: Find a way to reduce the dict
return render_template('admin_users.html', users=users)
@app.route('/admin/users/add', methods=['GET', 'POST'])
g.db.execute('insert into users (email, name, organization, password, is_admin) values (?, ?, ?, ?, ?)',
[request.form['email'], request.form['username'], request.form['organization'], password, admin])
g.db.commit()
- # :TODO:maethor:120528: Send mail
- flash(u'Le nouvel utilisateur a été créé avec succès', 'success')
- return redirect(url_for('home'))
+ user = query_db('select * from users where email = ?', [request.form["email"]], one=True)
+ if user:
+ for role in request.form.getlist('roles'):
+ # :TODO:maethor:120528: Check if this role exist
+ if query_db('select id from roles where id = ?', role, one=True) is None:
+ abort(401)
+ g.db.execute('insert into user_role values (?, ?)', [user['id'], role])
+ g.db.commit()
+ # :TODO:maethor:120528: Send mail
+ flash(u'Le nouvel utilisateur a été créé avec succès', 'success')
+ return redirect(url_for('admin_users'))
+ else:
+ flash(u'Une erreur s\'est produite.', 'error')
else:
flash(u"Vous devez spécifier une adresse email.", 'error')
- return render_template('admin_user_new.html')
+ groups = query_db('select * from roles where system=0')
+ return render_template('admin_user_new.html', groups=groups)
#-------------
# Roles admin
system INTEGER default 0 not null
);
+create table user_role (
+ id_user INTEGER,
+ id_role INTEGER,
+ FOREIGN KEY(id_user) REFERENCES users(id),
+ FOREIGN KEY(id_role) REFERENCES roles(id),
+ PRIMARY KEY(id_user, id_role)
+);
+
create table votes (
id INTEGER primary key autoincrement,
title TEXT not null,
</div>
</div>
<div class="control-group">
- <label class="control-label" for="role">Groupes</label>
+ <label class="control-label" for="roles">Groupes</label>
<div class="controls">
- <select name="role" id="role" multiple>
- <option selected>CA</option>
- <option>Membres</option>
+ <select name="roles" id="roles" multiple>
+ {% for group in groups %}
+ <option value="{{ group.id }}">{{ group.name }}</option>
+ {% endfor %}
</select>
</div>
</div>